/* dot11SmeEssLib.h - Contains the main definitions for Ess Mode.  */

/* Copyright 2004 Wind River Systems, Inc. */

/* 
Modification History
--------------------
02a,25aug04,rb  Wind River Wireless Ethernet Driver 2.0 FCS
*/

#ifndef __INCdot11SmeEssLibh
#define __INCdot11SmeEssLibh
#ifdef  __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "vxWorks.h"

/**************************************************************************
*  DOT11_ESS_SM - State machine for the ESS SME
***************************************************************************/
typedef struct /* DOT11_ESS_SM */
    {
    STATUS  (*resetReqProcess)(DOT11_FW * pDot11);
    STATUS  (*joinReqProcess)(DOT11_FW * pDot11);
    STATUS  (*bssDiscoveredProcess)(DOT11_FW * pDot11);
    STATUS  (*authSuccessProcess)(DOT11_FW * pDot11);
    STATUS  (*authTimeoutProcess)(DOT11_FW * pDot11);
    STATUS  (*authFailProcess)(DOT11_FW * pDot11);
    STATUS  (*assocSuccessProcess)(DOT11_FW * pDot11);
    STATUS  (*assocFailProcess)(DOT11_FW * pDot11);
    STATUS  (*assocTimeoutProcess)(DOT11_FW * pDot11);
    STATUS  (*deauthProcess)(DOT11_FW * pDot11);
    STATUS  (*disassocProcess)(DOT11_FW * pDot11);
    STATUS  (*lqNoSignalProcess)(DOT11_FW * pDot11);
    STATUS  (*lqProbationProcess)(DOT11_FW * pDot11);
    STATUS  (*lqMakeDoProcess)(DOT11_FW * pDot11);
    STATUS  (*sharedKeyProcess)(DOT11_FW * pDot11);

    SEM_ID   smLockSem;
    MSG_Q_ID eventQueue;
    int currentState;
    int stateTaskId;

    } DOT11_ESS_SM;

#define DOT11_ESS_STATE_TASK_NAME           "tEssState%d"
#define DOT11_ESS_STATE_TASK_PRI            66
#define DOT11_ESS_STATE_TASK_STACK          (4 * 1024)
#define DOT11_ESS_STATE_MAX_MSG             64
#define DOT11_ESS_STATE_TASK_SHUTDOWN_TIME  ((sysClkRateGet() / 50) + 2)
#define DOT11_ESS_STATE_LOCK_TIME           (sysClkRateGet() / 4)

/*****************************************************************************
* DOT11_ESS_EVENTS - Events that drive the ESS state machine  
*****************************************************************************/

/* RESET_REQ - can be called from any state.  Will bring the device back to the
NO_ESS state */
#define DOT11_ESS_RESET_REQ                 1

/* JOIN_REQ - called from any state.  Used to join a new BSS.  Will move the 
SM to the SEARCHING state */
#define DOT11_ESS_JOIN_REQ                  2

/* BSS_DISCOVERED - generated from the SCANNING or LINK_PROB states when a new
BSS matching the scanning criteria has been found */
#define DOT11_ESS_BSS_DISCOVERED            3

/* AUTH_SUCCESS - Generated from the AUTHENTICATING state when the 
authentication was successful */
#define DOT11_ESS_AUTH_SUCCESS              4

/* TIMEOUT - Generated from the AUTHENTICATING or ASSOCIATING states when the
station failed to complete assoc or auth in the specified time */
#define DOT11_ESS_AUTH_TIMEOUT              5

/* AUTH_FAIL - Generated by the AUTHENTICATING state when the AP denies the 
station authentication */
#define DOT11_ESS_AUTH_FAIL                 6

/* ASSOC_SUCCESS - Generated by the ASSOCIATING state when the station 
completes association successfully */
#define DOT11_ESS_ASSOC_SUCCESS             7

/* ASSOC_FAIL - Generated by the ASSOCIATING state when the station is denied
association */
#define DOT11_ESS_ASSOC_FAIL                8 

/* ASSOC_TIMEOUT - Generated by the ASSOCIATING state when the AP does not 
respond*/
#define DOT11_ESS_ASSOC_TIMEOUT             9 

/* DEAUTH - Generated in response to a user request to de-authenticate the 
station.  If associated, a deassociation occurs before the actual 
deauthentication packet is sent out. */
#define DOT11_ESS_DEAUTH                    10

/* DISASSOC - Generated in response to a user request to disassociate the 
station.  */
#define DOT11_ESS_DISASSOC                   11

/* LQ_NO_SIGNAL - Generated in the CONNECTED state when the station has not
received a packet (or beacon) from the AP in a set time period. */
#define DOT11_ESS_LQ_NO_SIGNAL              12

/* LQ_PROBATION - Generated in the CONNECTED state when the average signal
level drops below a set threshold */
#define DOT11_ESS_LQ_PROBATION              13

/* LQ_MAKE_DO - Generated in the LINK_PROB state when a stronger AP in the ESS
cannot be found */
#define DOT11_ESS_LQ_MAKE_DO                14

/* SHUTDOWN - a pseudo-event that shuts down the ESS state machine and frees
all resources used by it */
#define DOT11_ESS_SHUTDOWN                  15

/* DOT11_ESS_SKA - generated from ATHENTICATING state when shared key
is being used.  It signifies the receipt of stage 2, and triggers the
transmittion of stage 3. */
#define DOT11_ESS_SKA                       16


/*****************************************************************************
* DOT11_ESS_STATES - Possible states for the ESS SM           
*****************************************************************************/
typedef enum 
    {
    SME_ESS_NOESS = 0,     /* Base initialized state.  Not operational */
    SME_ESS_SCANNING,      /* Looking for a specific ESS or any ESS */
    SME_ESS_AUTHENTICATING,/* Chose an ESS - sent auth seq 1 */
    SME_ESS_AUTH_SHARED,   /* In the middle of a SKA exchange, sent #3 */
    SME_ESS_ASSOCIATING,   /* Authenticated.  Send Assoc Req. */
    SME_ESS_CONNECTED,     /* Authenticated and associated.  Fully connected*/
    SME_ESS_LINK_PROB,     /* Looking for better AP. Still connectect to old*/
    SNE_ESS_STATES_MAX
    } SME_ESS_STATE;

/*****************************************************************************
* DOT11_ESS_SCAN_MESSAGES - Messages passed to the ESS Scan task
******************************************************************************/
#define DOT11_ESS_SCAN_MAX_MSGS     16
#define DOT11_ESS_SCAN_TASK_PRI    (DOT11_ESS_STATE_TASK_PRI + 1)
#define DOT11_ESS_SCAN_TASK_STACK   4096
#define DOT11_ESS_SCAN_TASK_NAME    "tDot11Scan%d"
#define DOT11_ESS_SCAN_WAIT         (sysClkRateGet() / 4)

/* This is the amount of time that is required between probation periods.
If the device tried to enter probation more frequently than this, the
eevent will be dropped */
#define DOT11_ESS_PROBATION_MIN_DELAY (sysClkRateGet() * 30)

typedef enum
    {
    DOT11_ESS_SCAN_START,
    DOT11_ESS_SCAN_STOP,
    DOT11_ESS_PROB_START,
    DOT11_ESS_PROB_STOP    
    } DOT11_ESS_SCAN_MESSAGE;


#ifdef  __cplusplus
}
#endif /* __cplusplus */
#endif /* __INCdot11SmeEssLibh */






